<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const input = [
            {
                username: 'zhangsan',
                starCount: 10,
                content: '嘻嘻嘻',
            },
            {
                username: 'lisi',
                starCount: 122,
                content: '嘿嘿',
            },
            {
                username: 'lisi',
                starCount: 99,
                content: '呵呵',
            },
            {
                username: 'zhangsan',
                starCount: 12,
                content: '哈哈哈',
            },
            {
                username: 'wangwu',
                starCount: 6,
                content: '嗯嗯',
            },
        ];

        const output = {
            zhangsan: {
                starCount: 22,
                commentCount: 2,
            },
            lisi: {
                starCount: 221,
                commentCount: 2,
            },
            wangwu: {
                starCount: 6,
                commentCount: 1,
            },
        };

        function getTotal(input) {
            const res = {};
            for (const { username, starCount } of input) {
                if (!res[username]) {
                    res[username] = {
                        starCount,
                        commentCount: 1,
                    };
                } else {
                    res[username].starCount += starCount;
                    res[username].commentCount++;
                }
            }
            return res;
        }
        console.log(getTotal(input));
    </script>
</body>
</html>